package com.power.sifa.net.formact.service;

import com.plf.common.utils.SpringHolder;
import com.plf.common.utils.StringUtil;
import com.power.sifa.net.model.enumeration.Tp_matter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public class FormNextFlyweight {
    /**
     * matid与service name的mapping关系
     */
    private static Map<String, String> matservicemap = new HashMap(16);

    static {
        matservicemap.put(Tp_matter.PUB_ADMREVIEW, "formNextAcceptImpl");
        matservicemap.put(Tp_matter.PUB_RESPOND, "formNextRespondImpl");
        matservicemap.put(Tp_matter.PUB_CORRECTION, "formNextCondeployImpl");
        matservicemap.put(Tp_matter.PUB_SUPERVISE, "formNextSuperviseImpl");
    }

    public static FormNextService getInstanse(String matid) {
        //根据matid，选择子类
        String servicename = matservicemap.get(matid);
        if (StringUtil.isEmpty(servicename)) {
            log.info("matid未配置表单下一步服务类 -> " + matid);
            return null;
        }
        Object servicebean = SpringHolder.getBean(servicename);
        Assert.notNull(servicename, "无法根据matid找到表单下一步服务bean" + matid);

        FormNextService service = (FormNextService) servicebean;
        return service;
    }
}
